package com.mango.ch02;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

public class NaturalKeyGroupingComparator extends WritableComparator {
    public NaturalKeyGroupingComparator() {
        /**
         * 一定要写 super(CompositeKey.class, true); 否则报下面的错 Error:
         * java.lang.NullPointerException at
         * org.apache.hadoop.io.WritableComparator.compare(WritableComparator.java:157)
         *
         */
        super(CompositeKey.class, true);
    }

    @SuppressWarnings("rawtypes")
    @Override
    public int compare(WritableComparable a, WritableComparable b) {
        // TODO Auto-generated method stub
        //只要股票代码相同就分到同一个组里 不管时间
        CompositeKey k1 = (CompositeKey) a;
        CompositeKey k2 = (CompositeKey) b;
        return k1.getStockSymbol().compareTo(k2.getStockSymbol());
    }

}
